<script>

import addEnergyFee from "@/components/system-base/modules/addEnergyFee.vue";

export default {
  computed: {
    addEnergyFee() {
      return addEnergyFee
    }
  },
  data() {
    return {
      param: {
        content: {
          name: ''
        }
      },
      tableList: {
        item: null,
        hidden: false,
        activeName: '水',
        data:[]
      }
    }
  },
  mounted() {
    this.fetchData()
  },
  methods: {
    queryButtonClick: function () {
      this.fetchData()
    },
    fetchData: function () {
      this.tableList.hidden = false
      this.$axios({url:'/ems/client/base/energy/fee/list',data: this.param}).then((content) => {
        this.tableList.data = content.list
        if (this.tableList.data.length > 0 && !this.tableList.activeName) {
          this.tableList.activeName = this.tableList.data[0].energyName
        }
      })
    },
    deleteData: function (id) {
      this.$axios({url:'/ems/client/base/energy/fee/delete',data: {content:id}}).then((content) => {
        if (content) {
          this.$message("操作成功")
          this.fetchData()
        }
      })
    },
    clickAddEnergyFee: function () {
      this.tableList.hidden = true
      this.tableList.item = {}
    },
    tableItemDetail: function (item) {
      this.tableList.hidden = true
      this.tableList.item = item
    }
  },
  components: {
      addEnergyFee: () => import("@/components/system-base/modules/addEnergyFee.vue")
  }
}
</script>

<template>
  <div>
    <addEnergyFee v-if="tableList.hidden"  :tableList="tableList" :fetchTableData="fetchData"/>
    <el-row v-if="!tableList.hidden">
      <el-col :span="24">
        <label>名称：</label><el-input v-model="param.content.name" placeholder="请输入内容" style="width: 200px"></el-input>
        &nbsp;
        <el-button type="primary" plain @click="queryButtonClick">查询</el-button>
        <el-button type="primary" plain @click="clickAddEnergyFee">添加</el-button>
      </el-col>
      <el-col :span="24" style="margin-top: 20px;">
        <el-tabs v-model="tableList.activeName" type="border-card">
          <el-tab-pane v-for="item in tableList.data" :key="item.energyId" :label="item.energyName" :name="item.energyName">
            <el-table :data="item.data" border style="width: 100%">
              <el-table-column prop="id" label="序号" width="150" align="center"> </el-table-column>
              <el-table-column prop="name" label="名称" width="200"> </el-table-column>
              <el-table-column prop="buildingName" label="适用建筑" width="150"> </el-table-column>
              <el-table-column prop="instituteName" label="适用院所" width="150"> </el-table-column>
              <el-table-column prop="areaCode" label="适用行政区" width="150"> </el-table-column>
              <el-table-column prop="numRange" label="月度累计值范围"> </el-table-column>
              <el-table-column prop="timeRange" label="时间范围"> </el-table-column>
              <el-table-column prop="value" label="兑货币比例(一单位兑换人民币分)" width="250" align="center"> </el-table-column>
              <el-table-column label="操作" >
                <template slot-scope="scope">
                  <el-button @click="tableItemDetail(scope.row)" type="text" size="small">查看</el-button>
                  <el-button type="text" size="small" @click="deleteData(scope.row.id)">删除</el-button>
                </template>
              </el-table-column>
            </el-table>
          </el-tab-pane>
        </el-tabs>
      </el-col>
    </el-row>
  </div>
</template>

<style>

</style>
